package cyou.breathe.blog.folder.domain.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import cyou.breathe.blog.api.folder.request.FolderCreateDirectoryRequest;
import cyou.breathe.blog.api.folder.request.FolderCreateRootRequest;
import cyou.breathe.blog.api.folder.request.FolderUpdateRequest;
import cyou.breathe.blog.datasource.domain.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * @author: breathe
 * @createTime: 2025-08-30
 */
@Setter
@Getter
@TableName("folders")
public class Folder extends BaseEntity {

    private String folderName;

    private Long parentId;

    private Long userId;

    private Integer count;

    @TableField(exist = false)
    private List<Folder> children;

    public Folder createRootFolder(FolderCreateRootRequest request) {
        this.folderName = request.getFolderName();
        this.userId = request.getUserId();
        this.parentId = 0L;
        return this;
    }

    public Folder createDirectory(FolderCreateDirectoryRequest request) {
        this.folderName = request.getFolderName();
        this.parentId = request.getParentId();
        this.userId = request.getUserId();
        return this;
    }

    public Folder updateFolder(FolderUpdateRequest request) {
        this.folderName = request.getFolderName();
        this.parentId = request.getParentId();
        this.userId = request.getUserId();
        return this;
    }
}
